<template>
	<div>
		<wsSmPanel :page="table.page" @simple-query="query"  @page-change="query">
			<div slot="query_form">
				<Form :model="queryForm" :label-width="100" inline>
					<FormItem label="店铺名称">
			            <Input v-model="queryForm.shop" placeholder="请输入"></Input>
			        </FormItem>
			        <FormItem label="商品名称">
			            <Input v-model="queryForm.name" placeholder="请输入"></Input>
			        </FormItem>
				</Form>
			</div>
			<div slot="list_operate">
			</div>
			<div slot="list_data">
				<ws-table :data="table.data" style="width: 100%" @selection-change="handleSelectionChange">
					<ws-table-column type="selection" width="55"></ws-table-column>
					<ws-table-column align="center" prop="shop" label="店铺名称"></ws-table-column>
					<ws-table-column align="center" prop="name" label="商品名称"></ws-table-column>
					<ws-table-column align="center" label="价格">
						<template slot-scope="scope">
							<span style="color: red;" v-text="scope.row.price"></span>
						</template>
					</ws-table-column>
				</ws-table>
			</div>
		</wsSmPanel>
	</div>
</template>

<script>
	import Util from '../../../common/util.js';
	import Common from '../../../common/common.js';
	export default {
		props: {
			newProduct: { // 是否新品
    			type: Boolean,
    			default: true
    		}
		},
		data() {
			return {
				queryForm: {
					name: '',
					shop:''
				},
				table: {
					data: [],
					page: {
						total: 0, //总条数
						pageNum: 1, //当前页
						pageSize: 10 //每页显示条数
					},
					selections: [] //选中列表
				},
			}
		},
		methods: {
			query() {
				let name_ = this.queryForm.name;
				let shop_ = this.queryForm.shop;
				if(Util.vad.isBlank(name_) || Util.vad.isBlank(shop_)) {
					this.$Message.info('商品数量太多,请根据条件搜索哦~');
					return;
				}
				let pageSize = this.table.page.pageSize;
				let pageNum = this.table.page.pageNum;
				const _this = this;
				//0.上新 1.折扣
				let status = this.newProduct ? 0 : 1;
				this.axios.get('/ws/ops/v2/product/query/' + status + '/' + pageSize + '/' + pageNum, {params: this.queryForm}).then(response => {
					var res = response.data;
					var resMeta = res.meta;
					if (0 == resMeta.code) {
						_this.buildPageData(res.data);
					} else {
						_this.$Message.warning(resMeta.message);
					}
				});
			},
			buildPageData(data_) {
				this.table.data = data_.list;
				this.table.page.total = data_.total;
			},
			handleSelectionChange(val) {
				this.table.selections = val;
			},
			getSelections() {
				return this.table.selections;
			},
			resetForm() {
				this.queryForm.name = '';
				this.queryForm.shop = '';
				this.table.page.total = 0;
				this.table.page.pageNum = 1;
				this.table.page.pageSize = 10;
				this.table.data = [];
				this.table.selections = [];
			}
		}
	}
</script>

<style>
</style>